#include "Line.h"

Line::Line(Vector3f * points)
{
	mPoints = points;
}

Line::~Line(void)
{
}
int Line::returnType()
{
	return AShape::TYPE_LINE;
}
void Line::drawGL()
{
	glColor3f((*mColor)[0],(*mColor)[1],(*mColor)[2]);
	glBegin(GL_LINES);
	glVertex3d(mPoints[0][0],mPoints[0][1],mPoints[0][2]);
	glVertex3d(mPoints[1][0],mPoints[1][1],mPoints[1][2]);
	glEnd();

	glBegin(GL_POINTS);
	glVertex3d(mPoints[0][0],mPoints[0][1],mPoints[0][2]);
	glVertex3d(mPoints[1][0],mPoints[1][1],mPoints[1][2]);
	glEnd();
}

Vector3f* Line::clickOnMarker(Vector2f* mousePos, int indexX, int indexY, int markerRadius)
{
	float mouseX = (*mousePos)[0];
	float mouseY = (*mousePos)[1];

	for (int j = 0; j < 2; j++)
	{
		if (mouseX > (mPoints[j][indexX]-markerRadius) && mouseX < (mPoints[j][indexX]+markerRadius))
		{
			if (mouseY > (mPoints[j][indexY]-markerRadius) && mouseY < (mPoints[j][indexY]+markerRadius))
			{
				return &mPoints[j];
			}
		}
	}
	return NULL;
}

float Line::perimeterLength()
{
	return std::sqrt(std::pow(mPoints[1][0] - mPoints[0][0], 2) + std::pow(mPoints[1][1] - mPoints[0][1], 2)+ std::pow(mPoints[1][2] - mPoints[0][2], 2));
}
